package master2;

/**
 * @author chenyw
 * @date 2022/9/28 19:32
 * 单调递增的数字
 */
public class M738monotoneIncreasingDigits {
    public int monotoneIncreasingDigits(int n) {
        int i = 1;
        int res = n;
        while (i <= res / 10) {
            //每次取两个数
            int tmp = res / i % 100;
            i *= 10;
            if (tmp / 10 > tmp % 10) {
                res = res / i * i - 1;
            }
        }
        return res;
    }
}
